package cn.kgc.mes.type.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.access.prepost.PreAuthorize;

import cn.kgc.mes.common.core.plus.response.Result;
import cn.kgc.mes.common.core.plus.response.ResultUtil;
import cn.kgc.mes.common.core.plus.dto.common.CommonDataPageResponse;
import cn.kgc.mes.common.core.plus.response.StatusResponse;

import cn.kgc.mes.type.domain.vo.MdVendorVo;
import cn.kgc.mes.type.business.MdVendorBusiness;

/**
 * 供应商控制器
 * 
 * @author cly
 * @date 2025-09-14
 */
@RestController
@RequestMapping("/vendor/vendor")
public class MdVendorController {

    @Resource
    MdVendorBusiness business;

    /**
     * 分页查询供应商列表
     */
//    @PreAuthorize("@ss.hasPermi('vendor:vendor:list')")
    @PostMapping("/page")
    public Result page(@RequestBody MdVendorVo vo) {
        CommonDataPageResponse<MdVendorVo> response = business.page(vo);

        return ResultUtil.success(response);
    }

    /**
     * 获取供应商详细信息
     */
//    @PreAuthorize("@ss.hasPermi('vendor:vendor:query')")
    @PostMapping("/info")
    public Result info(@RequestBody MdVendorVo vo) {

        MdVendorVo info = business.info(vo);

        return ResultUtil.success(info);
    }

    /**
     * 新增供应商
     */
//    @PreAuthorize("@ss.hasPermi('vendor:vendor:add')")
    @PostMapping("/add")
    public Result add(@RequestBody MdVendorVo vo) {

        StatusResponse response = business.add(vo);
        if (response.getSuccess() == false) {
            return ResultUtil.fail(response.getMsg());
        }

        return ResultUtil.success(response);
    }

    /**
     * 修改供应商
     */
//    @PreAuthorize("@ss.hasPermi('vendor:vendor:edit')")
    @PostMapping("/update")
    public Result update(@RequestBody MdVendorVo vo) {

        StatusResponse response = business.update(vo);
        if (response.getSuccess() == false) {
            return ResultUtil.fail(response.getMsg());
        }

        return ResultUtil.success(response);
    }

    /**
     * 删除供应商
     */
//    @PreAuthorize("@ss.hasPermi('vendor:vendor:remove')")
    @PostMapping("/delete")
    public Result delete(@RequestBody MdVendorVo vo) {

        StatusResponse response = business.delete(vo);
        if (response.getSuccess() == false) {
            return ResultUtil.fail(response.getMsg());
        }

        return ResultUtil.success(response);
    }

}
